package br.com.massai.model.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

@Entity
@Table(name="CONTROLE_ACESSO", schema = "PORTAL")
@SequenceGenerator(name = "seqControleAcesso", sequenceName = "seq_controle_acesso", allocationSize = 1)
@NamedQueries({
	@NamedQuery(name = "ControleAcesso.findLastAccess", query = "SELECT c FROM ControleAcesso c WHERE c.id = (SELECT MAX(ca.id) FROM ControleAcesso ca WHERE ca.usuario = :usuario)"), 
	@NamedQuery(name = "ControleAcesso.findAll", query = "SELECT c FROM ControleAcesso c")
})
public class ControleAcesso implements Serializable {
	
	private static final long serialVersionUID = 736998416620891689L;

	@Id
	@Column(name = "ID_CONTROLE_ACESSO")
	@GeneratedValue(generator = "seqControleAcesso", strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DATA_LOGIN")
	private Date dataLogin;
	
	@Column(name = "IP_LOGIN", length = 15, columnDefinition = "VARCHAR(15)")
	private String ip;
	
	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	private Usuario usuario;
	
	public ControleAcesso() { }
	
	public ControleAcesso(Date datalogin, String ip, Usuario user) {
		super();
		this.dataLogin = datalogin;
		this.ip = ip;
		this.usuario = user;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getDataLogin() {
		return dataLogin;
	}

	public void setDataLogin(Date dataLogin) {
		this.dataLogin = dataLogin;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Usuario getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	} 

}
